﻿@using Model.WXshopBuiness
@using Model.WXshopBuiness.DTO
@using Xproject.Util
@{
    Layout = null;

    string Domain = CommonHelper.GetAppSettings("Domin");
    Address DefaultAddress = (Address)ViewData["DefaultAddress"];
    List<Address> myaddress = (List<Address>)ViewData["Address"];
    decimal defaultKDF = decimal.Parse(ViewData["DefaultKDF"].ToString());
    UserProductKanJia UPKJ = (UserProductKanJia)ViewData["userKanJiaInfo"];
    decimal price = Model.ThatTimeSalePrice;    
}
@model OrderInfoModel
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
    <title>订单详情</title>

    <link href="~/Content/bootstrap.css" rel="stylesheet" />
    <link href="~/Content/css/shop/home.css" rel="stylesheet" />

    <link href="http://at.alicdn.com/t/font_u5tafk2orz281tt9.css" rel="stylesheet" type="text/css" />

    <style>
        html, body {
            height: 100%;
            margin: 0px;
            font-size: 12px;
        }
        .form-group {
            border-bottom: 1px solid #ececec;
            overflow: hidden;
            margin-top: 5px;
            margin-bottom: 0;
        }

            .form-group .col-xs-4 {
                padding-left: 0;
                color: #333;
            }

            .form-group .col-xs-8 {
                padding: 0;
            }

        .control-label {
            line-height: 2.143em;
            text-align: right;
        }

        .form-control {
            box-shadow: none;
            padding: 0 0.429em;
            height: 2.143em;
            border: none;
        }

        .allAddress {
            width: 100%;
            height: 150px;
            background-color: #fff;
            opacity: 1;
            filter: alpha(opacity=1);
            position: fixed;
            left: 0;
            top: 60%;
            z-index: 1100;
            overflow-y: scroll;            
            height: 300px;
        }
        #allAddressdiv p  {
            text-align:left;
        }
        #allAddressdiv label {
            text-align: left;
        }
        .bg {
            background-color: #ccc;
            width: 100%;
            height: 100%;
            left: 0;
            top: 0; /*FF IE7*/
            filter: alpha(opacity=50); /*IE*/
            opacity: 0.5; /*FF*/
            z-index: 1;
            position: fixed !important; /*FF IE7*/
            position: absolute; /*IE6*/
            _top: expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2 : /*IE6*/
            document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2); /*IE5 IE5.5*/
        }
        /*The END*/
        .address-bg {
            width: 100%;
            height: 50%;
            background-color: #fff;
            opacity: 1;
            filter: alpha(opacity=1);
            position: fixed;
            left: 0;
            top: 50%;
            overflow-y:scroll;
            z-index: 1100;
        }
        
    </style>

</head>

<body>
    <div class="top_c">
        <a href="~/UserCenter/UserCenter" class="iconfont icon-jiantou-copy-copy"></a>
        <p class="titi">确认订单</p>
    </div>




    <!--内容-->

    @if (Model.OrderState == 1)
    {

        if (DefaultAddress != null)
        {
            <p class="d_min" style="margin-top:3em;font-size:1.26em;font-weight:bolder">收件人信息 <span onclick="UseOtherAdd()" style="display: inline-block;float: right;">使用其他地址</span></p>
            <div class="add" id="OrderAddressInfo">

                <p>@(DefaultAddress.Receiver)<i>@(DefaultAddress.Phone)</i></p>
                <p>@(DefaultAddress.Area + DefaultAddress.DetailAddress)</p>
                <div class="mo">
                    <label class="checkbox-inline">
                        <span>@(DefaultAddress.IsDefault == 1 ? "默认" : "")</span>
                        <span>@DefaultAddress.Tag</span>
                    </label>

                </div>
            </div>
        }
        else
        {
            <div class="add" style="padding-top:3rem" id="noreiveDiv">
                <p class="d_min" style="font-size:1.26em;font-weight:bolder" id="noreceiverP">
                    收件人信息(暂无)
                    <a id="noreceivera" href="#" onclick="AddAddressNow();" class="ming" style="text-align:right;font-weight:400;color:green">去添加</a>                    
                </p>
            </div>
            <div class="add" style="display:none;margin-top:3rem;" id="OrderAddressInfo">
                 
            </div>

            <div id="editContent" class="address-bg" style="display:none">
                <div style="background-color:#00ff63;height:2.5rem;font-size:1.4rem;">
                    <a href="#" onclick="CloseAddress();"><img alt="" src="~/Content/Image/shop/close.png" /></a>
                    <label style="margin-left:4rem;">新增收货地址</label>
                </div>
                <div class="">
                    <div class="container" style="background:#fff; padding-left:0px;padding-right:0px;">
                        <div class="form-group">
                            <label for="Receiver" class="col-xs-4 control-label" style="text-align:left;padding:0;margin:0">收货人姓名</label>
                            <div class="col-xs-8">
                                <input class="form-control" name="Receiver" id="Receiver" placeholder="请输入收货人的姓名" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="Phone" class="col-xs-4 control-label" style="text-align:left;padding:0;margin:0">手机号码</label>
                            <div class="col-xs-8">
                                <input class="form-control" name="Phone" id="Phone" placeholder="请输入您的手机号码" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="PostCode" class="col-xs-4 control-label" style="text-align:left;padding:0;margin:0">邮编</label>
                            <div class="col-xs-8">
                                <input class="form-control" name="PostCode" id="PostCode" placeholder="请输入邮编" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-xs-12 control-label" style="text-align:left;padding:0;margin:0">省市区</label>
                            <div class="col-xs-12">
                                <div id="Distpicker">
                                    <select class="control col-xs-4" id="sheng"></select>
                                    <select class="control col-xs-4" id="shi"></select>
                                    <select class="control col-xs-4" id="quyu"></select>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="Tag" class="col-xs-2 control-label" style="text-align:left;padding:0;margin:0">标签</label>
                            <div class="col-xs-6">
                                <input class="form-control" id="Tag" name="Tag" placeholder="请输入标签" value="@(Model!=null?Model.Tag:"")">
                            </div>
                            <div class="col-xs-4">
                                <input type="checkbox" class="checkbox" id="IsDefault" name="IsDefault" style="width:10px;float:left"><span>设为默认</span>
                            </div>
                        </div>
                        <div class="form-group" style="border-bottom:none;">
                            <label for="DetailAddress" class="col-xs-2 control-label" style="text-align:left;padding-left:0px;padding-right:0px;">详细地址</label>
                            <div class="col-xs-10">
                                <textarea name="DetailAddress" id="DetailAddress" placeholder="请输入您的详细地址" cols="2" rows="2" style="width:100%" required></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <input id="addressId" name="addressId" type="hidden" value="@(Model!=null?Model.AddressID:"")" />
                            <button onclick="saveit()" class="deng" style="margin-top:0.2em;">保 存</button>
                        </div>
                    </div>

                </div>
            </div>
        }

    }
    else
    {
        <div class="add" style="margin-top: 3em;">
            <p class="d_min" style="font-size:1.26em;font-weight:bolder">收件人信息</p>
            <p>@(Model.Receiver)<i>@(Model.receivePhone)</i></p>
            <span>@(Model.DetailAddress)</span>
            <div class="mo">
                <label class="checkbox-inline">
                    <span>@(Model.IsDefault == 1 ? "默认" : "")</span>
                    <span>@Model.Tag</span>
                </label>

            </div>
        </div>
    }

        <div class="deta" style="margin-top:0em">
            <p class="d_min" style="font-size:1.26em;font-weight:bolder">订单信息</p>
            <div class="leb">
                <div class="container">
                    <span class="hui" style="border-top:none;font-size:1.26em;">订单编号<i>@Model.OrderCode</i></span>
                    <span class="hui" style="font-size:1.26em;">下单时间<i>@Model.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</i></span>
                </div>
            </div>
            <p class="d_min" style="font-size:1.26em;font-weight:bolder">订单明细</p>
            <div class="leb">
                <a href="~/shop/business" class="d_ti">@Model.ProductName</a>
                <div class="container">
                    <div class="row">

                        <div class="col-xs-6">
                            <div> <img src="@(Model.Domain+Model.ProductImg)" /></div>
                        </div>
                        <div class="col-xs-6">
                            <span style="font-size:1.26em;">@Model.ShortDesc</span>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-12">
                            <p style="font-size:1.26em;">@Model.AllSpec</p>
                        </div>
                    </div>

                </div>
            </div>
            <p class="d_min">订单金额</p>
            
        <span class="pei" style="background-color: white">售价：<i>￥@(price.ToString("#0.00"))</i></span>
 
            <span class="pei" style="background-color: white">数量：<i>X @(Model.ProductNum)</i></span>
            <span class="pei" style="background-color: white">配送费<i>￥@(defaultKDF.ToString("#0.00"))</i></span>



            @if (ViewBag.HasKanJia)
    {

        <span class="pei" style="background-color: white;color:red;font-weight:800">砍价优惠<i>-￥@(UPKJ.AleradKanJiaMoney.ToString("#0.00"))</i></span>
}

            <span class="hui" style="background-color: white">其它优惠<i>-￥@Model.UseCoupon.ToString("#0.00")</i></span>
            @if (ViewBag.HasKanJia)
    {
        

        <span class="hui" style="background-color: white">总计￥@(((price * Model.ProductNum) + defaultKDF).ToString("#0.00"))&nbsp; 优惠￥@((Model.UseCoupon + UPKJ.AleradKanJiaMoney).ToString("#0.00"))<i>应付 <em>￥@(((price * Model.ProductNum) + defaultKDF - Model.UseCoupon - UPKJ.AleradKanJiaMoney).ToString("#0.00"))</em></i></span>
}
else
{
        <span class="hui" style="background-color: white">总计￥@(((price * Model.ProductNum) + defaultKDF).ToString("#0.00"))&nbsp; 优惠￥@(Model.UseCoupon.ToString("#0.00"))<i>应付 <em>￥@(((price * Model.ProductNum) + defaultKDF - Model.UseCoupon).ToString("#0.00"))</em></i></span>
}

        </div>
    @if (Model.OrderState == 1 || Model.OrderState == 0)
    {
        <div class="button bu_fi">
            @if (ViewBag.HasKanJia)
    {
        <a class="hui"><i><em>￥@(((price * Model.ProductNum) + defaultKDF - Model.UseCoupon - UPKJ.AleradKanJiaMoney).ToString("#0.00"))</em></i></a>
}
else
{
        <a class="hui"><i><em>￥@(((price * Model.ProductNum) + defaultKDF - Model.UseCoupon).ToString("#0.00"))</em></i></a>
}
            <a href="#" class="liji" onclick="DoPay('@(Model.OrderID)');">立即支付</a>
            <a href="#" onclick="DelThisOrder('@(Model.OrderID)')" class="qu">取消订单</a>
        </div>
    }



        <div class="allAddress" id="allAddressdiv" style="display:none">
            <div style="background-color:#00ff63;height:2.5rem;font-size:1.4rem;"><a href="javascript:closeDiv()"><img alt="" src="~/Content/Image/shop/close.png" /></a><label style="margin-left:4rem;">选择其他的收货地址</label></div>
            @foreach (Address ad in myaddress)
    {
        <div class="add" id="address@(ad.AddressID)" style="border-bottom: 1px solid #000;">
            <p>@ad.Receiver<i>@ad.Phone</i></p>
            <p>@(ad.Area+ ad.DetailAddress)</p>
            <div class="" style="text-align:left;">
                <label class="checkbox-inline">
                    <span>@(ad.IsDefault == 1 ? "默认" : "")</span>
                    <span>@ad.Tag</span>
                    <input type="checkbox" name="inlineCheckbox" id="inlineCheckbox@(ad.AddressID)" onclick="UserThisAddress('@ad.AddressID')" class="inlineCheckbox"> <label class="inlinelabel" id="inlinelabel@(ad.AddressID)">使用此地址</label>
                </label>
            </div>
        </div>
}

        </div>
    <div id="bg" class="bg" style="display:none;"></div>

    <input type="hidden" id="hiddenAddressId" value="@ViewBag.AddressID" />
    @if (Model.OrderState == 1)
    {
        if (DefaultAddress == null)
        {
            <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        }
        else
        {
            <script src="~/Scripts/shop/jquery.min.js"></script>
        }
    }
    else
    {
        <script src="~/Scripts/shop/jquery.min.js"></script>
    }
    <script src="~/Scripts/iscroll.js"></script>

    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Content/layerui/layer.js"></script>
    <script src="~/Scripts/shop/index.js"></script>
    <script type="text/javascript">
        function DoPay(orderId) {
            var addressId = $("#hiddenAddressId").val();
            if (addressId == "") {
                layer.open({
                    content: '请选择收货地址！'
                    , btn: '我知道了'
                });
                return;
            }
            layer.open({ type: 2, shadeClose: false });
               $.ajax({
            type: "POST",
            url: '@(Domain)/Order/Pay',
            data: { orderID: orderId, addressId: addressId},
            cache: false,
            success: function (data) {
                if (data.Success) {
                    layer.open({
                        content: '下一步选择支付方式'
                        , skin: 'msg'
                        , time: 1 //2秒后自动关闭
                        , end: function () {
                            layer.closeAll('dialog');
                        }
                    });
                     
                    //跳转到微信支付页面
                    window.location.href = "@(Domain + "/Order/PaySelect?orderId=")" + data.OrderId  ;
                }
            }, error: function (data) {
                var t = data;
            }
        });
        }

        function AddAddressNow() {
            $("#editContent").fadeIn();
        }

        	  function DelThisOrder(orderId) {

                layer.open({
                    content: '您确定要删除此此订单吗？'
                    , btn: ['确定', '不要']
                    , yes: function (index) {
                        layer.open({ type: 2, shadeClose: false });
                         $.ajax({
                            type: "post",
                            url: "@(Domain + "/Order/DelThisOrder")",
                            dataType: "json",
                            data: { orderId: orderId },
                            success: function (data) {
                                if (data.Success == true) {
                                    layer.closeAll('dialog');
                                    layer.open({
                                        content: data.Data
                                        , skin: 'msg'
                                        , time: 2 //2秒后自动关闭
                                        , end: function () {
                                            layer.closeAll('dialog');
                                        }
                                    });
                                    window.location.href = "@(Domain)" + "/UserCenter/UserCenter";
                                }
                                else {
                                    layer.closeAll('dialog');
                                    layer.open({
                                        content: data.Data
                                        , skin: 'msg'
                                        , time: 2 //2秒后自动关闭
                                    });
                                }
                              }
                        })
                    }
                });
            }

        function UseOtherAdd() {
            $(".inlineCheckbox").show();
            $(".inlinelabel").show();
            $(".inlineCheckbox").removeAttr("checked");
            $("#allAddressdiv").show();
        }

        function UserThisAddress(addressid) {
            $("#inlineCheckbox" + addressid).hide();
            $("#inlinelabel" + addressid).hide();
            var newaddhtml = $("#address" + addressid).html();
            $("#OrderAddressInfo").html(newaddhtml);
            $("#hiddenAddressId").val(addressid);
            $("#allAddressdiv").hide();
        }
        function closeDiv() {
            $("#allAddressdiv").hide();
        }
        
    </script> 
    @if (Model.OrderState ==1) 
    {
        if (DefaultAddress == null)
        {
            <script src="~/Scripts/distpicker/distpicker.js"></script>
            <script type="text/javascript">
             $(document).ready(function () {
            var province = '';
            var city = '';
            var district = '';
            $('#Distpicker').distpicker(
                {
                    province: province,
                    city: city,
                    district: district
                }
            );
           });
            function CloseAddress() {
                $("#editContent").hide();
            }

    function saveit() {
        var addressId = $("#addressId").val();
        var sheng = $("#sheng").val();
        var shi = $("#shi").val();
        var quyu = $("#quyu").val();
        var DetailAddress = $("#DetailAddress").val();
        var Phone = $("#Phone").val();
        var PostCode = $("#PostCode").val();
        var Receiver = $("#Receiver").val();
        var isDefault = $("#IsDefault").prop('checked');
        var Tag = $("#Tag").val();
        var errorstr = "";
        var flag = true;
        if (DetailAddress == '') {
            flag = false;
            errorstr = "没有填写详细地址哦";
        }
        if (sheng == '' || shi == '' || quyu == '') {
            flag = false;
            errorstr = "没有填写所在省市区";
        }
        
        if (Phone == '') {
            flag = false;
            errorstr = "没有填写手机号码";
        }
        if (Receiver == '') {
            flag = false;
            errorstr = "没有填写收件人哦";
        }
        if (Phone != '') {
            var mobilePatternHK = /^(\+852\s)?[5689]{1}\d{7}$/;
                if ((/^1[34578]\d{9}$/.test(Phone)) || mobilePatternHK.test(Phone)) {

                   // flag = true;
                } else {
                    errorstr = ("手机号码有误，请重填");
                    flag = false;
                }                         
               
        }

        if (flag == false) {
            layer.open({
                content: errorstr
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
            return;
        }
                layer.open({ type: 2, shadeClose: false });
           $.ajax({
            type: "POST",
            url: '@(Domain)/Address/EditAddr',
            data: {
                addressId: addressId, sheng: sheng, shi: shi, quyu: quyu, DetailAddress: DetailAddress, Phone: Phone, PostCode: PostCode,
                Receiver: Receiver, Tag: Tag, IsDefault: isDefault},
            cache: false,

            success: function (data) {
                layer.open({
                    content: data.Data
                    , skin: 'msg'
                    , time: 2 //2秒后自动关闭
                    , end: function () {
                        layer.closeAll('dialog');
                    }
                });
                    $("#hiddenAddressId").val(data.AddressId);
                //追加一行div
                    var div = '' +
                        '<p>' + Receiver + '<i>' + Phone + '</i></p>' +
                        '<p>' + sheng + shi + quyu + DetailAddress + '</p>' +
                        '<div class="mo">' +
                        '<label class="checkbox-inline">' +
                        '<span></span>' +
                        '<span>' + Tag + '</span>' +
                        '</label>' +
                        '</div>';
                                                            
                    $("#noreiveDiv").hide();                    
                    $("#OrderAddressInfo").append(div);
                    $("#OrderAddressInfo").fadeIn();
                    CloseAddress();
            }
        });
    }

            </script>

        }
    }
</body>
</html>

